package com.example.w_library.log.priter.console;

import android.util.Log;

import com.example.w_library.log.base.WLogConfig;
import com.example.w_library.log.priter.WLogPrinter;

import org.jetbrains.annotations.NotNull;

/**
 * 控制台打印器
 */
public class WLogConsolePrinter implements WLogPrinter {

    @Override
    public void print(@NotNull WLogConfig config, int level, String tag, @NotNull String printString) {

        int len = printString.length();

        int countOfSub = len / WLogConfig.MAX_LEN;

        if (countOfSub > 0){
            int index = 0;

            for (int i = 0; i < countOfSub; i++) {

                Log.println(level,tag,printString.substring(index,index + WLogConfig.MAX_LEN));

                index += WLogConfig.MAX_LEN;
            }

            //打印剩余部分
            if (index != len){

                Log.println(level,tag,printString.substring(index,len));
            }
        }else {

            Log.println(level,tag,printString);
        }
    }
}
